package edu.syr.iis.web.controller;

import java.beans.PropertyEditorSupport;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import edu.syr.iis.web.model.DialogueAct;
import edu.syr.iis.web.model.DialogueActManager;

public class DialogueActPropertyEditor extends PropertyEditorSupport {
	
	DialogueActManager manager = null;	
	private static Log log = LogFactory.getLog(DialogueActPropertyEditor.class);

	
	public DialogueActPropertyEditor(DialogueActManager manager) {
		super();
		this.manager = manager;
	}

	

	@Override
	public void setAsText(String text)  throws IllegalArgumentException 
	{
		System.out.println("Entering: setAsText() with: " + text);
		
		if (text.equals("null"))
		{
			setValue(null);
		} 
		else
		{
			int id = Integer.parseInt(text);
			DialogueAct value = manager.getDialogueAct(id);

			if (value == null) {
				throw new IllegalArgumentException("No object found with id: " + id);
			}
			log.debug("  Setting value with \n" + value.getLogString());
			setValue(value);
		}
	}
}
